//
//  AppDelegate.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/9/12.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "AppDelegate.h"
#import "GuideController.h"
#import "IQKeyboardManager.h"
#import "CoachTabBarController.h"
#import "LoginBySecretController.h"
#import "AppDelegate+UPush.h"
#import <Bugly/Bugly.h>
#import "VersionCheck.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //注册百度地图
    [[LocationService shareInstance] configurationParameter];
    //腾讯bugly
    [Bugly startWithAppId:BUGLY];
    //键盘
    [self openIQKeyBoard];
    //推送
    [self configureUMessageWithAppKey:UPUSH launchOptions:launchOptions];
    //引导页
    [self guideVC];
    //版本检测
    [[VersionCheck shareInstance] checkVersionFromAppStore];
    return YES;
}

#pragma mark ==========引导页==========
- (void)guideVC{
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *rootVc = [[UIViewController alloc]init];
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"userMessage"] == nil) {//跳转至登录
        rootVc = [[UINavigationController alloc] initWithRootViewController:[[LoginBySecretController alloc] init]];
    }else {//跳转至主界面
        [UserMessage sharedInstance].model = [UserModel mj_objectWithKeyValues:[[NSUserDefaults standardUserDefaults] objectForKey:@"userMessage"]];
        [[NSUserDefaults standardUserDefaults] synchronize];
        rootVc = [CoachTabBarController shareLZHTabbarController];
    }
    self.window.rootViewController = rootVc;
    [self.window makeKeyAndVisible];
}

#pragma mark ==========键盘==========
- (void)openIQKeyBoard{
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    keyboardManager.enable = YES; // 控制整个功能是否启用
    keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘
    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义
    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
    keyboardManager.enableAutoToolbar = YES; // 控制是否显示键盘上的工具条
    keyboardManager.shouldShowToolbarPlaceholder = YES; // 是否显示占位文字
    keyboardManager.keyboardDistanceFromTextField = 20.0f; // 输入框距离键盘的距离
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    [[VersionCheck shareInstance] checkVersionFromAppStore];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
